/**
 * 
 */
package com.kexinde.wjifen.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Component;

import com.kexinde.wjifen.dao.impl.ConsumptionRecordDao;
import com.kexinde.wjifen.dao.impl.NormalUserDao;
import com.kexinde.wjifen.dao.impl.ShopDao;
import com.kexinde.wjifen.dao.impl.WorkerDao;
import com.kexinde.wjifen.model.ConsumptionRecord;
import com.kexinde.wjifen.model.NormalUser;
import com.kexinde.wjifen.model.Shop;
import com.kexinde.wjifen.model.Worker;
import com.kexinde.wjifen.service.IConsumptionRecordManager;
import com.kexinde.wjifen.vo.PageInfo;

/**
 * @author vincent
 *
 */
@Component("consumptionRecordManager")
public class ConsumptionRecordManager implements IConsumptionRecordManager {

	private ConsumptionRecordDao consumptionRecordDao;
	private ShopDao shopDao;
	private WorkerDao workerDao;
	private NormalUserDao normalUserDao;
	@Override
	public List<ConsumptionRecord> showShopAllConsumptionRecords(long shopId) {
		// TODO Auto-generated method stub
		Shop shop=shopDao.findById(shopId);		
		return shop.getConsumptionRecords();
	}

	@Override
	public List<ConsumptionRecord> showShopPersonalConsumptionRecord(
			long shopId, String normalUserUserName) {
		// TODO Auto-generated method stub
		NormalUser normalUser=normalUserDao.findByName(normalUserUserName);
		return consumptionRecordDao.findByShopAndNormalUser(shopId, normalUser.getId());
	}

	@Override
	public List<ConsumptionRecord> showPersonalAllConsumptionRecords(
			String normalUserUserName) {
		// TODO Auto-generated method stub
		NormalUser normalUser=normalUserDao.findByName(normalUserUserName);
		return normalUser.getConsumptionRecords();
	}

	@Override
	public boolean add(String workerUserName,String normalUserPhone, double money) {
		// TODO Auto-generated method stub
		Worker worker=workerDao.findByName(workerUserName);
		NormalUser normalUser=normalUserDao.findByName(normalUserPhone);
		ConsumptionRecord record=new ConsumptionRecord();
		record.setMoney(money);
		record.setNormalUser(normalUser);
		record.setWorkerId(worker.getId());
		record.setShop(worker.getShop());
		record.setTime(new Date());
		return consumptionRecordDao.doInsert(record);
	}

	@Override
	public boolean delete(ConsumptionRecord consumptionRecord) {
		// TODO Auto-generated method stub
		return consumptionRecordDao.doDelete(consumptionRecord);
	}

	@Override
	public boolean modify(ConsumptionRecord consumptionRecord) {
		// TODO Auto-generated method stub
		return consumptionRecordDao.doUpdate(consumptionRecord);
	}



}
